package com.example.springboot.controller;

import com.example.springboot.pojo.Admin;
import com.example.springboot.pojo.Result;
import com.example.springboot.service.AdminService;
/*import com.example.springboot.utils.JwtUtils;*/
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class LoginController {
    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Result login(@RequestBody Admin admin){
        log.info("登录:{}",admin);
        Admin a = adminService.login(admin);
        if (a != null){
            Map<String, Object> claims = new HashMap<>();
            /*claims.put("id",a.getId());
            claims.put("name",a.getName());*/
            claims.put("username",a.getUsername());
            /*String jwt = JwtUtils.generateJwt(claims);*/
            /*return Result.success(jwt);*/
        }
        return a != null ? Result.success():Result.error("用户名或密码错误，登录失败");
    }

}